﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestConfirm.aspx.cs" Inherits="Customer_Profile.TestConfirm" %>

<%@ Register assembly="DevExpress.Web.ASPxEditors.v9.3, Version=9.3.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script language="javascript">
        var textSeparator = ";";
        function OnListBoxSelectionChanged(listBox, args) {
            if (args.index == 0)
                args.isSelected ? listBox.SelectAll() : listBox.UnselectAll();
            UpdateSelectAllItemState();
            UpdateText();
        }
        function UpdateSelectAllItemState() {
            IsAllSelected() ? checkListBox.SelectIndices([0]) : checkListBox.UnselectIndices([0]);
        }
        function IsAllSelected() {
            for (var i = 1; i < checkListBox.GetItemCount(); i++)
                if (!checkListBox.GetItem(i).selected)
                    return false;
            return true;
        }
        function UpdateText() {
            var selectedItems = checkListBox.GetSelectedItems();
            checkComboBox.SetText(GetSelectedItemsText(selectedItems));
        }
        function SynchronizeListBoxValues(dropDown, args) {
            checkListBox.UnselectAll();
            var texts = dropDown.GetText().split(textSeparator);
            var values = GetValuesByTexts(texts);
            checkListBox.SelectValues(values);
            UpdateSelectAllItemState();
            UpdateText();  // for remove non-existing texts
        }
        function GetSelectedItemsText(items) {
            var texts = [];
            for (var i = 0; i < items.length; i++)
                if (items[i].index != 0)
                    texts.push(items[i].value);
            return texts.join(textSeparator);
        }
        function GetValuesByTexts(texts) {
            var actualValues = [];
            var value = "";
            for (var i = 0; i < texts.length; i++) {
                value = GetValueByText(texts[i]);
                if (value != null)
                    actualValues.push(value);
            }
            return actualValues;
        }
        function GetValueByText(text) {
            for (var i = 0; i < checkListBox.GetItemCount(); i++)
                if (checkListBox.GetItem(i).value.toUpperCase() == text.toUpperCase())
                    return checkListBox.GetItem(i).value;
            return null;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lbl" runat="server"></asp:Label>
       <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
       <dx:ASPxDropDownEdit ClientInstanceName="checkComboBox" ID="ASPxDropDownEdit1" 
            SkinID="CheckComboBox" Width="210px" runat="server" EnableAnimation="False" ReadOnly="True">
            <DropDownWindowTemplate>
                <dx:ASPxListBox Width="100%" Height="300px" ID="listBox" ClientInstanceName="checkListBox" SelectionMode="CheckColumn" runat="server"  SkinID="CheckComboBoxListBox">
                <ClientSideEvents SelectedIndexChanged="OnListBoxSelectionChanged" />
                </dx:ASPxListBox>
                <table style="width:100%"><tr><td align="right">
                    <dx:ASPxButton ID="ASPxButton1" AutoPostBack="False" runat="server" Text="Close">
                        <ClientSideEvents Click="function(s, e){ checkComboBox.HideDropDown(); }"/>
                    </dx:ASPxButton>
                </td></tr></table>
            </DropDownWindowTemplate>
            <ClientSideEvents TextChanged="SynchronizeListBoxValues" DropDown="SynchronizeListBoxValues" />
       </dx:ASPxDropDownEdit>
    </div>
    </form>
</body>
</html>